Puzzle 5 Explanation: Raw Strings
Understand the functions of \t and \n.
We'll cover the following
Try it yourself#
Try running the code below to see the result for yourself.
Explanation#
There are two different ways to represent string literals in the Go spec1: raw string literals and interpreted string literals.
Raw strings are enclosed in backticks. Interpreted strings are enclosed in
quotes. In raw strings, \ has no special meaning, so the \t is two characters,
backslash, and the letter t. If it were an interpreted string, \t would be interpreted as the tab character.
Apart from the usual \t (tab), \n (newline), and others, we can use Unicode
code points in interpreted strings. For example, fmt.Println("\u2122") will print ™
.
Raw strings are commonly used to create multiline strings.
Puzzle 5: A Raw Diet
Puzzle 6: Are We There Yet?